package level.editor.window;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.OceanTheme;

/*
 * Handles the look and feel of the editor. Modify variables LOOKANDFEEL and
 * THEME to change the appearance of the editor.
 */

public class LookAndFeel
{
	private static final String LOOKANDFEEL = "System"; // "System"/"Motif"/"GTK"
	private static final Object THEME = "Metal"; // "Metal"/"DefaultMetal"/"Ocean"

	public static void initLookAndFeel()
	{
		String lookAndFeel = null;

		if (LOOKANDFEEL != null)
		{
			if (LOOKANDFEEL.equals("Metal"))
			{
				lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
				// an alternative way to set the Metal L&F is to replace the
				// previous line with:
				// lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
			}
			else if (LOOKANDFEEL.equals("System"))
			{
				lookAndFeel = UIManager.getSystemLookAndFeelClassName();
			}
			else if (LOOKANDFEEL.equals("Motif"))
			{
				lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
			}
			else if (LOOKANDFEEL.equals("GTK"))
			{
				lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
			}
			else
			{
				System.err
						.println("Unexpected value of LOOKANDFEEL specified: "
								+ LOOKANDFEEL);
				lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
			}
			try
			{
				UIManager.setLookAndFeel(lookAndFeel);

				// If L&F = "Metal", set the theme

				if (LOOKANDFEEL.equals("Metal"))
				{
					if (THEME.equals("DefaultMetal"))
					{
						MetalLookAndFeel
								.setCurrentTheme(new DefaultMetalTheme());
					}
					else if (THEME.equals("Ocean"))
					{
						MetalLookAndFeel.setCurrentTheme(new OceanTheme());
					}
					// else
					// {
					// MetalLookAndFeel.setCurrentTheme(new TestTheme());
					// }
					UIManager.setLookAndFeel(new MetalLookAndFeel());
				}
			}
			catch (ClassNotFoundException e)
			{
				System.err
						.println("Couldn't find class for specified look and feel:"
								+ lookAndFeel);
				System.err
						.println("Did you include the L&F library in the class path?");
				System.err.println("Using the default look and feel.");
			}
			catch (UnsupportedLookAndFeelException e)
			{
				System.err.println("Can't use the specified look and feel ("
						+ lookAndFeel + ") on this platform.");
				System.err.println("Using the default look and feel.");
			}
			catch (Exception e)
			{
				System.err.println("Couldn't get specified look and feel ("
						+ lookAndFeel + "), for some reason.");
				System.err.println("Using the default look and feel.");
				e.printStackTrace();
			}
		}
	}

}
